const express = require('express')

const router = express.Router()

const users = require('../../data/router/user')
const routers = require('../../data/router/routes.js')

router.post('/postRoutes', (req, res) => {
    res.setHeader('content-type', 'text/html;charset=utf-8')
    // res.setHeader('Access-Control-Allow-Origin','*')
    const { uid } = req.body
    let authRotuterInfo = []
    if (uid) {
        const userInfo = users.filter(user => user.id === uid)[0]
        userInfo.hasAuth.map((rid) => {
            routers.map((router) => {
                if (router.id === rid) {
                    authRotuterInfo.push(router)
                }
            })
        })
    }
    res.end(JSON.stringify(authRotuterInfo))
})

//暴露 router
module.exports = router;